<template>
    <h1>显示会员列表</h1>
    姓名：
    <input type="text"  placeholder="请输入" v-model="querydata.Name">
    性别：
    <select v-model="querydata.Sex">
        <option value="1">男</option>
        <option value="0">女</option>
    </select>
    <input type="button" value="查询" @click="Show">
    <table border="1">
        <thead>
            <tr>
                <th>会员名称</th>
                <th>会员号</th>
                <th>会员电话</th>
                <th>会员等级</th>
                <th>会员状态</th>
                <th>会员性别</th>
                <th>时间</th>
            </tr>
        </thead>
        <tbody>
            <tr v-for="h in data">
                <td>{{h.Name }}</td>
                <td>{{ h.Num }}</td>
                <td>{{ h.Phone }}</td>
                <td>{{ h.Level }}</td>
                <td>{{ h.State }}</td>
                <th>{{h.Sex==1?"男":"女"}}</th>
                <th>{{ moment(h.Timess).format("YYY-MM-DD HH:mm:ss") }}</th>
                <td>
                    <input type="button" value="编辑" @click="Update(h.Id)">
                </td>
                <td>
                    <input type="button" value="删除" @click="Delete(h.Id)">
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import moment from 'moment';
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
import router from '@/router';

const Delete=(val:any)=>{
    if(confirm("确认删除吗")){
        axios.delete("https://localhost:7069/api/Member/DeleteMember",{params:{Id:val}}).then(res=>{
        if(res.data>0){
            alert('删除成功')
            Show();
        }
        else{
            alert('删除失败')
           
        }
    })
    }
    
}


const Update=(val:any)=>{
    router.push({path:'/ShowDetailView',query:{Id:val}});
}


const data=ref([{
   "Id": 0,
    "Name": "",
    "Num": "",
    "Phone": "",
    "Level": "",
    "State": "",
    "Sex": 0,
    "Timess": "2025-03-24T08:41:24.507Z"
}])


const querydata=ref({
    Name:'',
    Sex:0
})


onMounted(()=>{
    Show()
})

const Show=()=>{
    axios.get("https://localhost:7069/api/Member/GetMembers",{params:querydata.value}).then(res=>{
        data.value=res.data;
    })
}


</script>



